/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.eclipsecon.dui.swtmodel.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EDataTypeUniqueEList;

import org.eclipsecon.dui.swtmodel.MColor;
import org.eclipsecon.dui.swtmodel.MControl;
import org.eclipsecon.dui.swtmodel.MFont;
import org.eclipsecon.dui.swtmodel.MLayoutData;
import org.eclipsecon.dui.swtmodel.MSWT;
import org.eclipsecon.dui.swtmodel.SwtmodelPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>MControl</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.eclipsecon.dui.swtmodel.impl.MControlImpl#getForeground <em>Foreground</em>}</li>
 *   <li>{@link org.eclipsecon.dui.swtmodel.impl.MControlImpl#getBackground <em>Background</em>}</li>
 *   <li>{@link org.eclipsecon.dui.swtmodel.impl.MControlImpl#getFont <em>Font</em>}</li>
 *   <li>{@link org.eclipsecon.dui.swtmodel.impl.MControlImpl#getLayoutdata <em>Layoutdata</em>}</li>
 *   <li>{@link org.eclipsecon.dui.swtmodel.impl.MControlImpl#getId <em>Id</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public abstract class MControlImpl extends StyledElementImpl implements MControl {
	/**
	 * The cached value of the '{@link #getForeground() <em>Foreground</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getForeground()
	 * @generated
	 * @ordered
	 */
	protected MColor foreground;

	/**
	 * The cached value of the '{@link #getBackground() <em>Background</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBackground()
	 * @generated
	 * @ordered
	 */
	protected MColor background;

	/**
	 * The cached value of the '{@link #getFont() <em>Font</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFont()
	 * @generated
	 * @ordered
	 */
	protected MFont font;

	/**
	 * The cached value of the '{@link #getLayoutdata() <em>Layoutdata</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLayoutdata()
	 * @generated
	 * @ordered
	 */
	protected MLayoutData layoutdata;

	/**
	 * The default value of the '{@link #getId() <em>Id</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getId()
	 * @generated
	 * @ordered
	 */
	protected static final String ID_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getId() <em>Id</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getId()
	 * @generated
	 * @ordered
	 */
	protected String id = ID_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected MControlImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return SwtmodelPackage.Literals.MCONTROL;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public MColor getForeground() {
		return foreground;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetForeground(MColor newForeground, NotificationChain msgs) {
		MColor oldForeground = foreground;
		foreground = newForeground;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, SwtmodelPackage.MCONTROL__FOREGROUND, oldForeground, newForeground);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setForeground(MColor newForeground) {
		if (newForeground != foreground) {
			NotificationChain msgs = null;
			if (foreground != null)
				msgs = ((InternalEObject)foreground).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - SwtmodelPackage.MCONTROL__FOREGROUND, null, msgs);
			if (newForeground != null)
				msgs = ((InternalEObject)newForeground).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - SwtmodelPackage.MCONTROL__FOREGROUND, null, msgs);
			msgs = basicSetForeground(newForeground, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SwtmodelPackage.MCONTROL__FOREGROUND, newForeground, newForeground));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public MColor getBackground() {
		return background;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetBackground(MColor newBackground, NotificationChain msgs) {
		MColor oldBackground = background;
		background = newBackground;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, SwtmodelPackage.MCONTROL__BACKGROUND, oldBackground, newBackground);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setBackground(MColor newBackground) {
		if (newBackground != background) {
			NotificationChain msgs = null;
			if (background != null)
				msgs = ((InternalEObject)background).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - SwtmodelPackage.MCONTROL__BACKGROUND, null, msgs);
			if (newBackground != null)
				msgs = ((InternalEObject)newBackground).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - SwtmodelPackage.MCONTROL__BACKGROUND, null, msgs);
			msgs = basicSetBackground(newBackground, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SwtmodelPackage.MCONTROL__BACKGROUND, newBackground, newBackground));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public MFont getFont() {
		return font;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetFont(MFont newFont, NotificationChain msgs) {
		MFont oldFont = font;
		font = newFont;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, SwtmodelPackage.MCONTROL__FONT, oldFont, newFont);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setFont(MFont newFont) {
		if (newFont != font) {
			NotificationChain msgs = null;
			if (font != null)
				msgs = ((InternalEObject)font).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - SwtmodelPackage.MCONTROL__FONT, null, msgs);
			if (newFont != null)
				msgs = ((InternalEObject)newFont).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - SwtmodelPackage.MCONTROL__FONT, null, msgs);
			msgs = basicSetFont(newFont, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SwtmodelPackage.MCONTROL__FONT, newFont, newFont));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public MLayoutData getLayoutdata() {
		return layoutdata;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetLayoutdata(MLayoutData newLayoutdata, NotificationChain msgs) {
		MLayoutData oldLayoutdata = layoutdata;
		layoutdata = newLayoutdata;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, SwtmodelPackage.MCONTROL__LAYOUTDATA, oldLayoutdata, newLayoutdata);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setLayoutdata(MLayoutData newLayoutdata) {
		if (newLayoutdata != layoutdata) {
			NotificationChain msgs = null;
			if (layoutdata != null)
				msgs = ((InternalEObject)layoutdata).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - SwtmodelPackage.MCONTROL__LAYOUTDATA, null, msgs);
			if (newLayoutdata != null)
				msgs = ((InternalEObject)newLayoutdata).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - SwtmodelPackage.MCONTROL__LAYOUTDATA, null, msgs);
			msgs = basicSetLayoutdata(newLayoutdata, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SwtmodelPackage.MCONTROL__LAYOUTDATA, newLayoutdata, newLayoutdata));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getId() {
		return id;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setId(String newId) {
		String oldId = id;
		id = newId;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SwtmodelPackage.MCONTROL__ID, oldId, id));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case SwtmodelPackage.MCONTROL__FOREGROUND:
				return basicSetForeground(null, msgs);
			case SwtmodelPackage.MCONTROL__BACKGROUND:
				return basicSetBackground(null, msgs);
			case SwtmodelPackage.MCONTROL__FONT:
				return basicSetFont(null, msgs);
			case SwtmodelPackage.MCONTROL__LAYOUTDATA:
				return basicSetLayoutdata(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case SwtmodelPackage.MCONTROL__FOREGROUND:
				return getForeground();
			case SwtmodelPackage.MCONTROL__BACKGROUND:
				return getBackground();
			case SwtmodelPackage.MCONTROL__FONT:
				return getFont();
			case SwtmodelPackage.MCONTROL__LAYOUTDATA:
				return getLayoutdata();
			case SwtmodelPackage.MCONTROL__ID:
				return getId();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case SwtmodelPackage.MCONTROL__FOREGROUND:
				setForeground((MColor)newValue);
				return;
			case SwtmodelPackage.MCONTROL__BACKGROUND:
				setBackground((MColor)newValue);
				return;
			case SwtmodelPackage.MCONTROL__FONT:
				setFont((MFont)newValue);
				return;
			case SwtmodelPackage.MCONTROL__LAYOUTDATA:
				setLayoutdata((MLayoutData)newValue);
				return;
			case SwtmodelPackage.MCONTROL__ID:
				setId((String)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case SwtmodelPackage.MCONTROL__FOREGROUND:
				setForeground((MColor)null);
				return;
			case SwtmodelPackage.MCONTROL__BACKGROUND:
				setBackground((MColor)null);
				return;
			case SwtmodelPackage.MCONTROL__FONT:
				setFont((MFont)null);
				return;
			case SwtmodelPackage.MCONTROL__LAYOUTDATA:
				setLayoutdata((MLayoutData)null);
				return;
			case SwtmodelPackage.MCONTROL__ID:
				setId(ID_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case SwtmodelPackage.MCONTROL__FOREGROUND:
				return foreground != null;
			case SwtmodelPackage.MCONTROL__BACKGROUND:
				return background != null;
			case SwtmodelPackage.MCONTROL__FONT:
				return font != null;
			case SwtmodelPackage.MCONTROL__LAYOUTDATA:
				return layoutdata != null;
			case SwtmodelPackage.MCONTROL__ID:
				return ID_EDEFAULT == null ? id != null : !ID_EDEFAULT.equals(id);
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (id: ");
		result.append(id);
		result.append(')');
		return result.toString();
	}

} //MControlImpl
